//index.js
//获取应用实例
var app = getApp()
Page({
	data: {
		root:'',
		siteroot:app.setting.siteroot,
		att_url:app.setting.att_url,
		account:app.setting.account,
		ShowAuthM:false,
		pagetitle:'会员' + '-' + app.setting.title,
		
	},
	onReady: function (){
		
	},
	onPullDownRefresh: function (){
		var the=this;
		var opt={};
		the.onLoad(opt);
		setTimeout(function(){
			wx.stopPullDownRefresh()
		},1000);
	},
	onLoad: function (){
		var page=this;
		var ShowAuthM=page.data.ShowAuthM;
		wx.setNavigationBarTitle({'title':page.data.pagetitle});
		app.util.get(app.access,function(pagedata){
			//console.log('member');console.log(pagedata);
			if((!pagedata.item.nickname || !pagedata.item.avatar || pagedata.item.nickname=='匿名用户') && !app.isgetUserInfo){
					ShowAuthM=!ShowAuthM
			}
			page.setData({
				pagedata:pagedata,
				ShowAuthM:ShowAuthM,
				pluginnav:app.session.menus,
				action:app.access.plugin+'/'+app.access.action+'/'
			});
			if(!app.isShowSubMsg && pagedata.tmplIds && pagedata.tmplIds[0]){
				app.util.getsubmsgSet(pagedata.tmplIds,function(ShowSubMsg){
					if(ShowSubMsg){
						app.isShowSubMsg=true;
						page.setData({
							ShowSubMsg:true,
						});
					}
				});
			}
		});
	},
	info_login:function(e){
		//根据openid为用户登陆，此处尝试获取用户信息
		var the=this;
		app.util.getUserInfo(e,function(res){
			the.onLoad();
		});
		app.isgetUserInfo=true
		the.setData({
			ShowAuthM:false
		})
	},
	closeAuthM:function(){
		var the=this;
		the.setData({
			ShowAuthM:false
		})
	},
	show_vipcard:function(){
		var the=this;
		the.setData({
			show_vipcard:!the.data.show_vipcard
		})
	},
	addcard:function(e){
		var the=this;
		var data=evt.currentTarget.dataset;
	},
	//订阅消息
	SubscribeMessage: function () {
		var the=this
		var pagedata=the.data.pagedata
		the.setData({
				ShowSubMsg:false,
		});
		wx.requestSubscribeMessage({
			'tmplIds':pagedata.tmplIds,
			success:function (res) {
				console.log('SubscribeMessage success');console.log(res);
				if(res[pagedata.tmplIds[0]]=='accept'){
					
				}
			},
			fail:function (res) {
				console.log('SubscribeMessage fail');console.log(res);
			},
		})
	},
  	click:function(evt){
		//用户点击事件 data.func 为方法名，data.params 为调用参数！
		var data=evt.currentTarget.dataset;
		app.util[data.func](data.params);
	},
	click_tab:function(evt){
		//用户点击事件 data.func 为方法名，data.params 为调用参数！
		var data=evt.currentTarget.dataset;
		app.util.tab(data.params);
	},
	formSubmit:function(event){
		var data=event.detail.value;
		app.util.post('jy_weishop/member.index/post/',data);
	}
});